package com.lz.filter.servletFilter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


//本来只需要将过滤器添加@Compent注解即可生效
//但是添加了这个配置类可以细粒度的控制过滤器的执行顺序，以及指定过滤器的路径等
@Component
public class FilterConfig {
    @Resource
    private MyFilter myFilter;

    @Bean
    public FilterRegistrationBean<MyFilter> loggingFilter() {
        FilterRegistrationBean<MyFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(myFilter);
        registrationBean.addUrlPatterns("/test/*"); // 指定过滤器的路径
        return registrationBean;
    }
}